<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>疫情数据后台管理</title>
    <meta name="description" content="疫情数据后台管理">
    <meta name="keywords" content="疫情数据后台管理">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../static/plugins/elementui/index.css">
    <link rel="stylesheet" href="../static/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../static/css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>数据管理<small>百度热门话题管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>数据管理</el-breadcrumb-item>
            <el-breadcrumb-item>百度热门话题管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="关键词" v-model="queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="clickfindAll()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-button type="danger" class="butT" @click="getNewData()">获取最新数据</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="dt" label="时间" align="center"></el-table-column>
                <el-table-column prop="content" label="话题" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            {#<div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>#}
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增热门话题" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="更新时间" prop="dt">
                                    <el-date-picker
                                            v-model="formData.dt"
                                            type="datetime"
                                            value-format="yyyy-MM-dd HH:mm:ss"
                                            placeholder="选择日期时间">
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="话题">
                                    <el-input v-model="formData.content"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑热门话题" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataEditForm" :model="formData" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="更新时间" prop="dt">
                                    <el-date-picker
                                            v-model="formData.dt"
                                            type="datetime"
                                            placeholder="选择日期时间"
                                            readonly>
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="话题">
                                    <el-input v-model="formData.content"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../static/js/vue.js"></script>
<script src="../static/plugins/elementui/index.js"></script>
<script type="text/javascript" src="../static/js/jquery.min.js"></script>
<script src="../static/js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            queryString: null,//查询条件
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findAll();
        },
        methods: {
            //编辑
            handleEdit() {
                axios.post("/editHotSearch", this.formData).then((res) => {
                    if (res.data.status) {
                        this.$message({
                            type: 'success',
                            message: res.data.msg
                        })
                    } else {
                        this.$message.error(res.data.msg)
                    }
                    this.findAll();
                    this.dialogFormVisible4Edit = false;
                });
            },
            //添加
            handleAdd() {
                axios.post("/addHotSearch", this.formData).then((res) => {
                    this.dialogFormVisible = false;
                    if (res.data.status) {
                        //执行成功
                        this.findAll();
                        this.$message({
                            message: res.data.msg,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(res.data.msg);
                    }
                });
            },
            //点击查询
            clickfindAll() {
                axios.get("/findHotSearchByWord?word=" + this.queryString).then((res) => {
                    this.dataList = res.data.data;
                });
            },
            //查询所有
            findAll() {
                axios.get("/findAllHotSearch").then((res) => {
                    this.dataList = res.data.data;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.dialogFormVisible4Edit = true;
                //回显数据
                axios.get("/findHotSearchById?id=" + row.id).then((res) => {
                    if (res.data.status) {
                        this.formData = res.data.data;
                    } else {
                        //查询失败
                        this.$message.error(res.data.msg);
                    }
                });
            },
            // 删除
            handleDelete(row) {
                this.$confirm("确定要删除吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮。发送Ajax请求
                    axios.get("/deleteHotSearch?id=" + row.id).then((res) => {
                        if (res.data.status) {
                            //执行成功
                            this.$message({
                                message: res.data.msg,
                                type: 'success'
                            });
                            //重新进行分页查询
                            this.findAll();
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作取消'
                    });
                });
            },
            //获取最新数据
            getNewData() {
                this.$confirm("确定要获取最新数据吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    //用户点击确定按钮。发送Ajax请求
                    axios.get("/getNewHotSearchData").then((res) => {
                        if (res.data.status) {
                            this.$message({
                                message: res.data.msg,
                                type: 'success'
                            });
                            this.findAll()
                        } else {
                            //查询失败
                            this.$message.error(res.data.msg);
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '操作取消'
                    });
                });
            },
        }
    })
</script>
</html>